<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input v-model="query.value" clearable placeholder="输入搜索内容" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-select v-model="query.type" clearable placeholder="类型" class="filter-item" style="width: 130px">
          <el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />
        </el-select>
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="主键">
            <el-input v-model="form.id" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属公司">
            <el-input v-model="form.cid" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属项目">
            <el-input v-model="form.pid" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="创建时间">
            <el-input v-model="form.createTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="更新时间">
            <el-input v-model="form.updateTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="创建者">
            <el-input v-model="form.createBy" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="更新者">
            <el-input v-model="form.updateBy" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="名称">
            <el-input v-model="form.itemName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="危害或者潜在事件">
            <el-input v-model="form.hazardOrPotentialEvent" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="产生偏差的主要后果">
            <el-input v-model="form.mainConsequencesDeviations" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="现有安全控制措施">
            <el-input v-model="form.existingSafetyControlMeasures" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="建议改正/控制措施">
            <el-input v-model="form.controlMeasures" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="分析方法">
            <el-input v-model="form.analyticalMethod" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="事件发生可能性主键">
            <el-input v-model="form.itemHappenId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="事件发生可能性名称">
            <el-input v-model="form.itemHappenName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="暴露于危险环境的频繁程度主键">
            <el-input v-model="form.itemEId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="暴露于危险环境的频繁程度名称">
            <el-input v-model="form.itemEName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="发生事故事件偏差产生的后果严重性主键">
            <el-input v-model="form.itemCId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="发生事故事件偏差产生的后果严重性名称">
            <el-input v-model="form.itemCName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="R（风险值=L*E*C">
            <el-input v-model="form.itemR" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="风险等级主键">
            <el-input v-model="form.itemRiskId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="风险等级code">
            <el-input v-model="form.itemRiskCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="风险等级名称">
            <el-input v-model="form.itemRiskName" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="id" label="主键" />
        <el-table-column prop="cid" label="所属公司" />
        <el-table-column prop="pid" label="所属项目" />
        <el-table-column prop="createTime" label="创建时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="updateTime" label="更新时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.updateTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="createBy" label="创建者" />
        <el-table-column prop="updateBy" label="更新者" />
        <el-table-column prop="itemName" label="名称" />
        <el-table-column prop="hazardOrPotentialEvent" label="危害或者潜在事件" />
        <el-table-column prop="mainConsequencesDeviations" label="产生偏差的主要后果" />
        <el-table-column prop="existingSafetyControlMeasures" label="现有安全控制措施" />
        <el-table-column prop="controlMeasures" label="建议改正/控制措施" />
        <el-table-column prop="analyticalMethod" label="分析方法" />
        <el-table-column prop="itemHappenId" label="事件发生可能性主键" />
        <el-table-column prop="itemHappenName" label="事件发生可能性名称" />
        <el-table-column prop="itemEId" label="暴露于危险环境的频繁程度主键" />
        <el-table-column prop="itemEName" label="暴露于危险环境的频繁程度名称" />
        <el-table-column prop="itemCId" label="发生事故事件偏差产生的后果严重性主键" />
        <el-table-column prop="itemCName" label="发生事故事件偏差产生的后果严重性名称" />
        <el-table-column prop="itemR" label="R（风险值=L*E*C" />
        <el-table-column prop="itemRiskId" label="风险等级主键" />
        <el-table-column prop="itemRiskCode" label="风险等级code" />
        <el-table-column prop="itemRiskName" label="风险等级名称" />
        <el-table-column v-permission="['admin','jhaItem:edit','jhaItem:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudJhaItem from '@/api/jhaItem'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { id: null, cid: null, pid: null, createTime: null, updateTime: null, createBy: null, updateBy: null, itemName: null, hazardOrPotentialEvent: null, mainConsequencesDeviations: null, existingSafetyControlMeasures: null, controlMeasures: null, analyticalMethod: null, itemHappenId: null, itemHappenName: null, itemEId: null, itemEName: null, itemCId: null, itemCName: null, itemR: null, itemRiskId: null, itemRiskCode: null, itemRiskName: null }
export default {
  name: 'JhaItem',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '工作危害分析-子项', url: 'api/jhaItem', sort: 'id,desc', crudMethod: { ...crudJhaItem }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'jhaItem:add'],
        edit: ['admin', 'jhaItem:edit'],
        del: ['admin', 'jhaItem:del']
      },
      rules: {
      },
      queryTypeOptions: [
        { key: 'id', display_name: '主键' },
        { key: 'itemHappenName', display_name: '事件发生可能性名称' }
      ]
    }
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      const query = this.query
      if (query.type && query.value) {
        this.crud.params[query.type] = query.value
      }
      return true
    }
  }
}
</script>

<style scoped>

</style>
